package com.ebring.shareEducation.controller;

import com.ebring.shareEducation.bean.Currency;
import com.ebring.shareEducation.service.CurrencyService;
import com.ebring.shareEducation.utils.RspMsg;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Cola
 * Date  2018-12-08 11:10
 */

@RestController
public class CurrencyController {

    @Autowired
    CurrencyService currencyService;

    /**
     * 增加虚拟币
     *
     * @return
     */
    @PostMapping("/currency/addMoney")
    public RspMsg addMoney(Currency currency) {
        return currencyService.addMoney(currency);
    }


    /**
     * 查询所有虚拟币
     *
     * @return
     */
    @GetMapping("/currency/list")
    public RspMsg<Currency> select() {
        return currencyService.selectTask();
    }

    /**
     * 修改任务
     */
    @PostMapping("/currency/update")
    public RspMsg<Currency> updateTask(Currency currency) {
        return currencyService.updateTask(currency);
    }

    /**
     * 根据任务ID删除任务
     *
     * @param currencyId
     * @return
     */

    @PostMapping("/currency/deleteById")
    public RspMsg<Currency> deleteById(String currencyId) {
        return currencyService.deleteById(currencyId);
    }


    /**
     * 虚拟币模糊查询
     *
     * @param cname
     * @param time
     * @return
     */
    @GetMapping("/currency/select")
    @ApiOperation(value="虚拟币模糊查询", notes="虚拟币模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cname", value = "中文名字", required = true, dataType = "String"),
            @ApiImplicitParam(name = "time", value = "起始时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "times", value = "终止时间", required = true, dataType = "String"),

            @ApiImplicitParam(name = "pageNum", value = "页数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "总页数", required = true, dataType = "Integer")
    })
    public RspMsg<List<Currency>> select(String cname, String time,String times, Integer pageNum, Integer pageSize) {

        if (pageNum == null) {
            pageNum = 1;

        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        return currencyService.select(cname,time,times);
    }
}
